//
//  LWOriginalView.m
//  1.28  weibo
//
//  Created by mac on 15/2/21.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "LWOriginalView.h"
#import "LWstatuses.h"
#import "UIImageView+WebCache.h"
#import "LWPhotoCollectionViewCell.h"
#import "LWPhotos.h"
@interface LWOriginalView ()

@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameLable;
@property (weak, nonatomic) IBOutlet UIImageView *vipView;
@property (weak, nonatomic) IBOutlet UILabel *timeLable;
@property (weak, nonatomic) IBOutlet UILabel *source;
@property (weak, nonatomic) IBOutlet UIImageView *verifiedView;
@property (weak, nonatomic) IBOutlet UILabel *contentLable;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintHeight;
/**
 *  原创微博的高度
 */
/**
 *  图片的高度
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionViewHeight;
/**
 *  图片容器
 */
@property (weak, nonatomic) IBOutlet UICollectionView *collectionCell;
/**
 *  被放大的图片
 */
@property (nonatomic,weak) UIImageView *currentImaeView;
/**
 *  被点击配图的原始frame
 */
@property (nonatomic,assign) CGRect originalFrame;
@end

@implementation LWOriginalView

- (void)awakeFromNib {
    //设置原创微博的最大宽度
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    self.contentLable.preferredMaxLayoutWidth = width - 10;
   
}
- (void)setStatus:(LWstatuses *)status{

    [super setStatus:status];
    //头像
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:self.status.user.profile_image_url] placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
    //姓名
    self.nameLable.text = self.status.user.name;
    //Vip
    if ([self.status.user isVip]) {
        self.vipView.hidden = NO;
        NSString *imageString = [NSString stringWithFormat:@"common_icon_membership_level%d",self.status.user.mbrank.intValue];
        self.vipView.image = [UIImage imageNamed:imageString];
        self.nameLable.textColor = [UIColor orangeColor];
    }else{
        
        self.vipView.hidden = YES;
        self.nameLable.textColor = [UIColor blackColor];
    }
    //时间
    self.timeLable.text = self.status.created_at;
    //来源
    self.source.text = self.status.source;
    //认证图标
    self.verifiedView.hidden = YES;
    switch (self.status.user.verified_type) {
        case LWUserVerifiedPersonal:
            self.verifiedView.hidden = NO;
            self.verifiedView.image = [UIImage imageNamed:@"avatar_vip"];
            break;
        case LWUserVerifiedOrgEnterprice:
        case LWUserVerifiedOrgMedia:
        case LWUserVerifiedOrgWebsite:
            self.verifiedView.hidden = NO;
            self.verifiedView.image = [UIImage imageNamed:@"avatar_enterprise_vip"];
            break;
        case LWUserVerifiedDaren:
            self.verifiedView.hidden = NO;
            self.verifiedView.image = [UIImage imageNamed:@"avatar_grassroot"];
            break;
            
        default:
            self.verifiedView.hidden = YES;
            break;
    }
    //文本内容
    self.contentLable.text = self.status.text;
    //原创微博的高度
    CGFloat contentViewHeight = [self.contentLable systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    self.constraintHeight.constant = self.contentLable.y + contentViewHeight + 10;
    //判断是否有配图
    NSInteger count = self.status.pic_urls.count;
    if (count > 0) {
        NSInteger row = 0;
        //1.计算有几行
        if (count % 3 == 0) {
            row = count / 3;
        }else{
            row = count / 3 + 1;
        }
        //3.设置配图的高度
        CGFloat photoHeight = 70;
        CGFloat photoMargin = 10;
        CGFloat photoCollectionHeight = row * photoHeight + (row - 1) * photoMargin;
        self.collectionViewHeight.constant = photoCollectionHeight;
        [self.collectionCell reloadData];
        //4.修改原创微博的高度
        self.constraintHeight.constant += photoCollectionHeight + 10;
        
    }else{
        
        self.collectionViewHeight.constant = 0;
    }

}

@end
